<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{asset('/js/web/frame/jedate/skin/jedate.css')}}">
    <script src="{{asset('/js/web/frame/jedate/jquery.jedate.js')}}"></script>
    <link rel="stylesheet" href="{{asset('/css/web/user/order_list.css')}}">
    <script src="{{asset('/js/web/user/order_list.js')}}"></script>
    <link rel="stylesheet" href="{{asset('/css/web/inc/header.css')}}">

</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.buyer_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title">我的订单</div>
                <div class="my-subnav ">
                    <ul>
                        <li class="{{array_get($search_params, 'order_status') ? : 'cur'}}"><a href="{{change_url_params(['order_status' => ''])}}" class="jm_hover">所有订单</a><i></i></li>
                        <li class="{{array_get($search_params, 'order_status') == 1 ? 'cur' : ''}}"><a href="{{change_url_params(['order_status' => '1'])}}" class="jm_hover">待付款</a><i></i></li>
                        <li class="{{array_get($search_params, 'order_status') == 2 ? 'cur' : ''}}"><a href="{{change_url_params(['order_status' => '2'])}}" class="jm_hover">待发货</a><i></i></li>
                        <li class="{{array_get($search_params, 'order_status') == 3 ? 'cur' : ''}}"><a href="{{change_url_params(['order_status' => '3'])}}" class="jm_hover">待收货</a><i></i></li>
                        <li class="{{array_get($search_params, 'order_status') == 4 ? 'cur' : ''}}"><a href="{{change_url_params(['order_status' => '4'])}}" class="jm_hover">交易完成</a><i></i></li>
                        <li class="{{array_get($search_params, 'order_status') == 5 ? 'cur' : ''}}"><a href="{{change_url_params(['order_status' => '5'])}}" class="jm_hover">已取消</a><i></i></li>
                    </ul>
                </div>
                <div class="search f-cb">
                    <form action="" method="GET">
                        <input name='order_code' type="text" class="text fl" placeholder="订单编号" value='{{array_get($search_params, 'order_code')}}'>
                        <select class="select fl" name='order_status'>
                            <option value='' {{!($order_status = array_get($search_params, 'order_status')) ? 'selected' : ''}}>所有订单类型</option>
                            <option value='1' {{$order_status == 1 ? 'selected' : ''}}>待付款</option>
                            <option value='2' {{$order_status == 2 ? 'selected' : ''}}>待发货</option>
                            <option value='3' {{$order_status == 3 ? 'selected' : ''}}>待收货</option>
                            <option value='4' {{$order_status == 4 ? 'selected' : ''}}>交易完成</option>
                            <option value='5' {{$order_status == 5 ? 'selected' : ''}}>已取消</option>
                        </select>
                        <div class="time fl">
                            下单时间：
                            <input value='{{array_get($search_params, 'order_at.start')}}' name='order_at[start]' type="text" class="timetext workinput wicon" id="inpstart" readonly>
                            <span>至</span>
                            <input value='{{array_get($search_params, 'order_at.end')}}' name='order_at[end]' type="text" class="timetext workinput wicon" id="inpend" readonly>
                        </div>
                        <input type="submit" class="submit fr" value="查询">
                    </form>
                </div>
                <div class="tit f-cb">
                    <div class="pr fl">订单商品</div>
                    <div class="pes fl">收货人 </div>
                    <div class="mon fl">金额</div>
                    <div class="sta fl">订单状态<i></i></div>
                    <div class="op fl">操作</div>
                </div>
                <div class="content">
                    @foreach($list as $order)
                    <div class="order">
                        <div class="boxtop f-cb">
                            {{--<input type="checkbox" class="check fl">--}}
                            <div class="number fl">订单编号：

                                @if($order['order_type']!=6)
                                    <a href="/member/buyer/orders/{{$order['id']}}">{{$order['order_code']}}</a>
                                @else
                                    <a href="javascript:void(0);">{{$order['order_code']}}</a>
                                @endif
                            </div>
                            <div class="business fl">商家：<a href="/shop/index/{{$order['shop_id']}}" target="_blank">{{array_get($order, 'shop.sp_name', '-')}}</a></div>
                            <a href="javascript:;" class="delete flr" data-id=></a>
                            <div class="time flr">下单时间：{{date('Y/m/d', strtotime($order['created_at']))}}</div>
                        </div>
                        <div class="info">
                            <table>
                                @if($order['order_type']==1 || $order['order_type']==6)
                                    {{--撮合产品和资质--}}
                                    @foreach($order['order_products'] as $key => $order_product)
                                    <tr>
                                        <td width="80" height="100" class="imgbox">
                                            @if($order['order_type']==6)
                                                <img src="{{$order_product['product_img_url']}}" width="80" height="80">
                                            @else
                                                <a target='_blank'  href="/product/info/{{$order_product['product_id']}}/{{$order_product['sku_id']}}">
                                                      <img src="{{$order_product['product_img_url']}}" width="80" height="80">
                                                </a>
                                            @endif
                                        </td>
                                        <td width="265" height="100" class="goods_name_box">
                                            <div class="goods_name">
                                                @if($order['order_type']==6)
                                                    {{$order_product['product_name']}}
                                                @else
                                                    <a target='_blank' href="/product/info/{{$order_product['product_id']}}/{{$order_product['sku_id']}}" >{{$order_product['product_name']}}</a>

                                                @endif
                                            </div>
                                        </td>

                                       <!--  <td width="345" height="100" class="goods_name_box">
                                            <div class="goods_name">

                                            </div>
                                            @if(!empty($order['order_product'][0]['attributes']))
                                            <div class="info_more_box" data-id="0" order-code="{{$order['order_code']}}">
                                                <div class="info_more info_more_{{$order['order_code']}}_0">更多信息</div>
                                                <div class="info_sjx"></div>
                                                <div class="info_con info_con_{{$order['order_code']}}_0">
                                                    @foreach ($order['order_product'][0]['attributes'] as $ko => $vo)
                                                    <span>{{$ko}}:</span><span>{{$vo}}</span>
                                                    @endforeach
                                                </div>
                                            </div>
                                            @endif
                                        </td> -->

                                        <td width="40" height="100" class="num" >×{{$order_product['quantity']}}</td>
                                        @if($key == 0)
                                            <td width="99" height="100" class="name" rowspan="{{$product_count = count($order['order_products'])}}">
                                                {{$order['receiver']}}
                                            </td>
                                            <td width="150" height="100" class="price" rowspan="{{$product_count}}">
                                                <div class="cost">
                                                    <span class="tt"><span class="rmb">￥</span>{{$order['order_money']}}</span>
                                                    <span class="yf">(含运费：¥{{$order['freight'] ? : '0.00'}})</span>
                                                </div>
                                            </td>
                                            <td width="150" height="100" class="statebox" rowspan="{{$product_count}}">
                                                <div>{{$order['order_status_name']}}</div>

{{--                                                @if($order['order_type']!=6)--}}
                                                    <a href="/member/buyer/orders/{{$order['id']}}" class="close jm_hover">订单详情</a>
                                                {{--@endif--}}
                                            </td>

                                            <td width="150" height="100" class="paybox" rowspan="{{$product_count}}">
                                                <div class="btnbox">
                                                    @if($order['order_status'] == 1)
                                                        <a href="/member/buyer/pay?order_codes={{$order['order_code']}}" data-id='' class="btn jm_btn8">立即付款</a>
                                                        <a href="javascript:;" class="order_cancel" data-id="{{$order['id']}}" data-code="{{$order['order_code']}}">取消订单</a>
                                                    @elseif($order['order_status'] == 2)
                                                        等待卖家发货
                                                    @elseif($order['order_status'] == 3)
                                                        <a href="javascript:;" class="order_confirm btn jm_btn8" data-id="{{$order['id']}}">确认收货</a>
                                                        <a href="javascript:;" class="logistics_info" data-id="{{$order['id']}}">查看物流</a>
                                                        <a href="javascript:;" class="return" data-sp="{{$order['shop_id']}}" >申请退货</a>

                                                    @elseif($order['order_status'] == 4)
                                                        @if($order['buyer_comment_status'])
                                                            <div class="btn_delivery revise_evaluate" data-id='{{$order["id"]}}' data-code="{{$order['order_code']}}">查看评价</div>
                                                        @else
                                                            <a href="/member/buyer/orders/{{$order['id']}}/comments/create" data-id='' class="btn jm_btn8">评价</a>
                                                        @endif
                                                    @endif
                                                </div>
                                            </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                @elseif($order['order_type']==4)
                                {{--配单--}}
                                    @foreach($order['items_products'] as $key => $items_product)
                                    <tr>
                                        <td width="80" height="100" class="imgbox">
                                            <div class="goods_name">{{$items_product['product_name']}}</div>
                                        </td>
                                        <!-- <td class="imgbox"></td> -->
                                        <td width="265" height="100" class="goods_name_box">
                                            <div class="goods_name">
                                                {{$items_product['model']?'型号：'.$items_product['model']:''}} {{$items_product['brand']?' | 品牌：'.$items_product['brand']:''}}
                                            </div>
                                        </td>

                                        <td width="40" height="100" class="num" >× {{$items_product['num']}}</td>
                                        @if($key == 0)
                                            <td width="99" height="100" class="name" rowspan="{{$product_count = count($order['items_products'])}}">
                                                {{$order['receiver']}}
                                            </td>
                                            <td width="150" height="100" class="price" rowspan="{{$product_count}}">
                                                <div class="cost">
                                                    <span class="tt"><span class="rmb">￥</span>{{$order['order_money']}}</span>
                                                    <span class="yf">({{in_array(1,$order['items_information']['quote_contain'])?'含票税':''}}    {{in_array(2,$order['items_information']['quote_contain'])?'含运费':''}}    {{in_array(3,$order['items_information']['quote_contain'])?'含安装':''}}    {{in_array(4,$order['items_information']['quote_contain'])?'含公报总价':''}}) </span>
                                                </div>
                                            </td>
                                            <td width="150" height="100" class="statebox" rowspan="{{$product_count}}">
                                                <div>{{$order['order_status_name']}}</div>
                                                <a href="/member/buyer/orders/{{$order['id']}}" class="close jm_hover">订单详情</a>
                                            </td>

                                            <td width="150" height="100" class="paybox" rowspan="{{$product_count}}">
                                                <div class="btnbox">
                                                    @if($order['order_status'] == 1)
                                                        <a href="/member/buyer/items/order/{{$order['id']}}" data-id='' class="btn jm_btn8">立即付款</a>
                                                        <a href="javascript:;" class="order_cancel" data-id="{{$order['id']}}" data-code="{{$order['order_code']}}">取消订单</a>
                                                    @elseif($order['order_status'] == 2)
                                                        等待卖家发货
                                                    @elseif($order['order_status'] == 3)
                                                        <a href="javascript:;" class="order_confirm btn jm_btn8" data-id="{{$order['id']}}">确认收货</a>
                                                        <a href="javascript:;" class="logistics_info" data-id="{{$order['id']}}">查看物流</a>
                                                        <a href="javascript:;" class="return">申请退货</a>
                                                    @endif
                                                </div>
                                            </td>
                                        @endif
                                    </tr>
                                    @endforeach
                                @endif
                            </table>
                        </div>
                    </div>
                    @endforeach
                </div>
                <div class="page">
                    @include('web.common.paginate', ['page' => $page])
                </div>
            </div>
        </div>
    </div>
</div>
<div class="suc_bg">
    <div class="suc_box">
        <div class="suc_box_top">
            <h2 class="bac_tit">申请退货</h2>
            <span class="cha">×</span>
        </div>
        <div class="suc_box_con">
           <h3 class="bac_title"><img src="{{asset('/img/web/inc/icon/tui.jpg')}}" alt="">&nbsp;&nbsp;如何退货？</h3>
           <h4 class="bac_cen">请先查收到货。通过《井井通》联系卖家客服 ，提交退货申请。 </h4>
           <p class="bac_notes">注：请与卖家联系协商达成，再进行确认收货的申请，避免退货带来的风险。<a href="{{asset('/helper/list/15')}}">了解更多退货 </a></p>
        </div>
        <div class="suc_box_bom">
            <a href="javascript:;" class="look contact_shop" data-sp="">已收到货，联系卖家退货</a>
            <a href="javascript:;" class="del">取消</a>
        </div>
    </div>
</div>
{{--评价--}}
<div class="revise_evaluate_bombbox" id='evaluate_bombbox'>
</div>

@include('web.layout.footer')
<script type="text/javascript">
    //url定义
    var express_url = "/member/buyer/orders/{id}/order_express/0";
    var order_update = '/member/buyer/orders/{id}';
    var order_cancel = "";
    //    var comment_url = '/member/seller/orders/{id}/user_comment/0';
        var comment_url = '/member/buyer/orders/comments/{id}/user_comment/{order_code}';

    //更多信息效果
    $('.info_more_box').hover(function () {
        var key = $(this).attr('data-id');
        var order_code = $(this).attr('order-code');
        $('.info_con_'+order_code+'_'+key).show();
        // $('.info_more').hide();
    },function () {
        var key = $(this).attr('data-id');
        var order_code = $(this).attr('order-code');
        $('.info_con_'+order_code+'_'+key).hide();
        // $('.info_more').show();
    });
    
    $(".order_cancel").on('click', function(event) {
        event.preventDefault();
        /* Act on the event */
        var order_id = $(this).data('id');
        var url = order_update.replace('{id}', order_id);
        layer.confirm('是否取消订单', {
            btn: ['确认', '取消'] //可以无限个按钮
        }, function (index) {
            $.ajax({
                url: url,
                type: 'PUT',
                dataType: 'json',
                data: {order_status: 5},
                success:function(data){
                  if(0==data.code){
                      layer.alert('取消成功！', {
                          icon: 1
                      }, function () {
                          window.location.reload();
                      });
                  }else{
                    alert(data.message);
                  }
                }
            });
        }, function (index, layero) {
            layer.close(index);
        });
        
    });

    $(".order_confirm").on('click', function(event) {
        event.preventDefault();
        var order_id = $(this).data('id');
        var url = order_update.replace('{id}', order_id);
        layer.confirm('是否确认收货', {
            btn: ['确认', '取消'] //可以无限个按钮
        }, function (index) {
            /* Act on the event */
            $.ajax({
                url: url,
                type: 'put',
                dataType: 'json',
                data: {order_status:4},
                success:function(data){
                    if(0==data.code){
                        window.location.reload();
                    }else{
                        layer.alert(data.message, {
                            icon: 0
                        }, function () {
                            window.location.reload();
                        });
                    }
                }
            });
        }, function (index, layero) {
            layer.close(index);
        });
    });
    //申请退货
    $(".return").on('click',function(){
        $(".suc_bg").show();
        var spid = $(this).attr('data-sp');
        $('.contact_shop').attr('data-sp',spid);
    })
    $(".suc_box_top .cha").on('click',function() {
        $(".suc_bg").hide();
    })
    $(".suc_box_bom .del").on('click',function() {
        $(".suc_bg").hide();
    })
    $(function () {
        //查看物流信息
        $('.logistics_info').click(function(){
            var order_id = $(this).data('id');
            var url = express_url.replace('{id}', order_id);
            $.get(
                url,
                {},
                function (data) {
                    $('html').append(data);
                }
            );
        });

        //申请退款
        $(".apply_refund").on('click', function(event) {
            event.preventDefault();
            /* Act on the event */
            var order_code = $(this).data('code');
            layer.confirm('是否确认退款？', {
                btn: ['确认', '取消'] //可以无限个按钮
            }, function (index) {
                $.ajax({
                    url: 'order_apply_refund',
                    type: 'GET',
                    dataType: 'json',
                    data: {order_code: order_code},
                    success:function(data){
                        if(0==data.code){
                            window.location.reload();
                        }else{
                            alert(data.message);
                        }
                    }
                });
            }, function (index, layero) {
                layer.close(index);
            });
        });

        //申请退货
        $(".apply_sales_return").on('click', function(event) {
            event.preventDefault();
            /* Act on the event */
            var order_code = $(this).data('code');
            layer.confirm('是否确认退货？', {
                btn: ['确认', '取消'] //可以无限个按钮
            }, function (index) {
                $.ajax({
                    url: 'order_apply_sales_return',
                    type: 'GET',
                    dataType: 'json',
                    data: {order_code: order_code},
                    success:function(data){
                        if(0==data.code){
                            window.location.reload();
                        }else{
                            alert(data.message);
                        }
                    }
                });
            }, function (index, layero) {
                layer.close(index);
            });

        });
        
        //评价
        $('.revise_evaluate').click(function(){
            var order_id = $(this).data('id');
            var order_code = $(this).data('code');
            var url = comment_url.replace('{id}', order_id);
            var url1=url.replace('{order_code}', order_code);
            $.ajax({
                url: url1,
                type: 'get',
                dataType: 'html',
                success: function (data) {
                    $('.revise_evaluate_bombbox').html(data);
                    $('.revise_evaluate_bombbox').show();
                    $('.bg_h').show();
                }
            });
        });
        
    })
</script>
</body>
</html>